//
//  ChildListViewController.m
//  IpadTestB
//
//  Created by edianzu on 2017/6/28.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChildListViewController.h"
#import "ChildListCell.h"
#import "AddChildView.h"
#import "PersonalInfoViewController.h"
#import "DSectionIndexItemView.h"
#import "DSectionIndexView.h"
@interface ChildListViewController ()<DSectionIndexViewDelegate,DSectionIndexViewDataSource,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIImagePickerControllerDelegate,SDDatePickerViewProtocol>
@property(nonatomic,strong)ChildModel * childModel;
@property(nonatomic,strong)ClassModel * classModel;
@property (nonatomic,strong)NSMutableDictionary * allDataDictionary;
@property(nonatomic,strong)AddChildView * AddChildView;
@property(nonatomic,strong)NSMutableArray * rightNowPaixuArr;
@property(nonatomic,assign)NSInteger rightChosenTag;
@property(nonatomic,assign)NSInteger fromBtnViewHeight;
@property(nonatomic,assign)CGFloat w;
@property(nonatomic,assign)CGFloat h;
@property (strong, nonatomic) DSectionIndexView * sectionIndexView;
@property (nonatomic,strong)UILabel * noDataLabel;
@end

@implementation ChildListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"学员名单";
    self.view.backgroundColor = UIColorFromRGB(241, 246, 248);
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont boldSystemFontOfSize:23*AutoScaleHorizontal],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    ////////////////左按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, 0, 35,35);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"navBack"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];;
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = 15;
    //将两个BarButtonItem都返回给NavigationItem
    self.navigationItem.leftBarButtonItems = @[spaceItem,leftBarBtn];

    //创建右边按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 140,35);
    rightBtn.layer.cornerRadius =10;
    rightBtn.backgroundColor = [UIColor whiteColor];
//    [rightBtn setImage:[UIImage imageNamed:@"navRightBtn"] forState:UIControlStateNormal];
    [rightBtn setTitle:@"＋ 添加孩子" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
    [rightBtn setTitleColor:UIColorFromRGB(28, 173, 146) forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightBarBtn = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];;
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItemm = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //将宽度设为负值
    spaceItemm.width = 5;
    //将两个BarButtonItem都返回给NavigationItem
    self.navigationItem.rightBarButtonItems = @[spaceItemm,rightBarBtn];
    
    //添加键盘监听事件
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShoww:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHidee:) name:UIKeyboardWillHideNotification object:nil];
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if (self.myTableView !=nil) {
        [self.myTableView removeFromSuperview];
    }
    if (self.noDataLabel !=nil) {
        [self.noDataLabel removeFromSuperview];
    }
    if (_sectionIndexView !=nil) {
        [_sectionIndexView removeFromSuperview];
    }
    [self getData];
//    [self.sectionIndexView reloadItemViews];
}


//- (void)viewWillLayoutSubviews
//{
//    [super viewWillLayoutSubviews];
//    
//    [_sectionIndexView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.myTableView.mas_right).with.offset(15*AutoScaleHorizontal);
//        make.centerY.mas_equalTo(self.myTableView.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(kSectionIndexWidth, kSectionIndexHeight));
//    }];
////    _sectionIndexView.frame = CGRectMake(CGRectGetWidth(self.myTableView.frame) - kSectionIndexWidth, (CGRectGetHeight(self.myTableView.frame) - kSectionIndexHeight)/2, kSectionIndexWidth, kSectionIndexHeight);
//    [_sectionIndexView setBackgroundViewFrame];
//}

#pragma mark 获取数据
-(void)getData{
    self.schoolNameArr = [[NSMutableArray alloc]initWithCapacity:0];//班级名称
    self.childArray = [[NSMutableArray alloc]initWithCapacity:0];//根据ZIMUPAIXUARR的顺序，把名字换成模型，最终显示。
    self.ZiMuArr = [[NSMutableArray alloc]initWithCapacity:0];//首字母数组
    self.ZiMuPaiXuArr = [[NSMutableArray alloc]initWithCapacity:0];//对数据以首字母重新排序的数组
    _rightNowPaixuArr = [[NSMutableArray alloc]initWithCapacity:0];//用来切换显示数据源。
    _rightChosenTag = 0;
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    
        
    //获取全部数据
    NSString* str = [user objectForKey:@"AllData"];
    
    
    //    NSLog(@"eee===%@",str);
    NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
    _allDataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    NSMutableArray * allClassArr  = [[NSMutableArray alloc]init];
    allClassArr = [_allDataDictionary objectForKey:@"ClassList"];//全部班级
    for (NSDictionary * dic in allClassArr) {
        [self.schoolNameArr addObject:[dic objectForKey:@"Name"]];//班级名称
    }
    NSMutableArray * allChildArr  = [[NSMutableArray alloc]init];
    allChildArr = [_allDataDictionary objectForKey:@"ChildList"];//全部
    for (NSMutableDictionary * dict in allChildArr) {//默认全部
        ChildModel * model = [ChildModel modelWithDictionary:dict];
        [_rightNowPaixuArr addObject:model];
    }
    
    NSMutableArray * childArr = [[NSMutableArray alloc]initWithCapacity:0];//准备对孩子名字排序的数组,放孩子名
    for (ChildModel*mod in _rightNowPaixuArr) {
        [childArr addObject:mod.ChildName];
    }
    self.ZiMuArr = [ChineseString IndexArray:childArr];//sectionheader
    [self.ZiMuArr insertObject:@"☆" atIndex:0];
    
    self.ZiMuPaiXuArr = [ChineseString LetterSortArray:childArr];
    //将模型数组从新排序
    for (NSMutableArray* array in self.ZiMuPaiXuArr) {
        NSMutableArray * smallArray = [[NSMutableArray alloc]initWithCapacity:0];
        for (NSString*str in array) {
            for (ChildModel*mod in _rightNowPaixuArr.reverseObjectEnumerator) {
                if ([str isEqualToString:mod.ChildName]) {
                    [smallArray addObject: mod];
                    [_rightNowPaixuArr removeObject:mod];
                }
            }
        }
        [self.childArray addObject:smallArray];
    }
    [user synchronize];
    
        
    
    [self setUpUi];
    
}

-(void)setUpUi{
    
    
    //按钮依赖VIEW
    self.classBtnView = [[UIView alloc]init];
    self.classBtnView.backgroundColor = UIColorFromRGB(241, 246, 248);
    //循环创建按钮
    _w = 0;//保存前一个button的宽以及前一个button距离屏幕边缘的距离
    _h = 30;//用来控制button距离父视图的高
    for (int i = 0; i<=_schoolNameArr.count; i++) {
        self.classBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.classBtn.tag = 100 + i;
        self.classBtn.backgroundColor = UIColorFromRGB(241, 246, 248);
        self.classBtn.layer.cornerRadius = 10;
        self.classBtn.layer.borderColor =UIColorFromRGB(26, 167, 157).CGColor;
        self.classBtn.layer.borderWidth = 1;
        [self.classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [self.classBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.classBtn.titleLabel.font = [UIFont boldSystemFontOfSize:20*AutoScaleHorizontal];
        [self.classBtn addTarget:self action:@selector(chooseClass:) forControlEvents:UIControlEventTouchUpInside];
        CGFloat length = 0;
//        CGFloat length0 = 0;
        if (i ==0) {
            self.classBtn.selected =YES;
            NSString * strall = @"全部";
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};
            length = [strall boundingRectWithSize:CGSizeMake(1024, 800) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width+60;
            [self.classBtn setTitle:strall forState:UIControlStateNormal];
            self.classBtn.backgroundColor = UIColorFromRGB(26, 167, 157);
        }else{
            self.classBtn.selected = NO;
            NSString * btnTitle = self.schoolNameArr[i-1];
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};
            length = [btnTitle boundingRectWithSize:CGSizeMake(1024, 800) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width+60;
            //为button赋值
            [self.classBtn setTitle:btnTitle forState:UIControlStateNormal];
        }

         self.classBtn.frame = CGRectMake((10+_w)*AutoScaleHorizontal, _h*AutoScaleVertical, (length + 40)*AutoScaleHorizontal , 35*AutoScaleVertical);

        if(170 + _w + length > 1024){
            _w = 0; //换行时将w置为0
            _h = _h + self.classBtn.frame.size.height + 10;//距离父视图也变化
            self.classBtn.frame = CGRectMake((10 + _w)*AutoScaleHorizontal, _h*AutoScaleVertical, (length + 15)*AutoScaleHorizontal, 35*AutoScaleVertical);//重设button的frame
        }
        
        _w  =self.classBtn.frame.size.width + self.classBtn.frame.origin.x;
//        h = h + self.classBtn.frame.size.height + 10;//距离父视图也变化
        
        [self.classBtnView addSubview:self.classBtn];
        
        
        UIImageView * btnImage = [[UIImageView alloc]init];
        btnImage.image = [UIImage imageNamed:@"btnImage"];
        if (i == 0) {
            btnImage.hidden =NO;
        }else{
        btnImage.hidden = YES;
        }
        btnImage.tag = 150+i;
        [self.classBtn addSubview:btnImage];
        [btnImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.classBtn.titleLabel.mas_centerY);
            make.left.mas_equalTo(self.classBtn.titleLabel.mas_right).with.offset(10*AutoScaleHorizontal);
            make.size.mas_equalTo(CGSizeMake(20*AutoScaleHorizontal, 20*AutoScaleVertical));
        }];
    }

    //共多少人
    self.numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, (_h+60)*AutoScaleVertical, 150*AutoScaleHorizontal, 20*AutoScaleVertical)];
    self.numberLabel.textColor = [UIColor blackColor];
    self.numberLabel.font = [UIFont boldSystemFontOfSize:20*AutoScaleHorizontal];
    NSInteger manyHeight = 0;
    for (NSMutableArray*arr in self.childArray) {
        for (ChildModel * mod in arr) {
            manyHeight +=1;
        }
    }
    self.numberLabel.text= [NSString stringWithFormat:@"共%d人",manyHeight];
    [self.classBtnView addSubview:self.numberLabel];
   
    
    if (self.childArray.count ==0) {
        _noDataLabel = [[UILabel alloc]init];
        _noDataLabel.text = @"还没有孩子";
        _noDataLabel.textColor = [UIColor blackColor];
        _noDataLabel.font = [UIFont boldSystemFontOfSize:25*AutoScaleHorizontal];
        [self.view addSubview:_noDataLabel];
        [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view.mas_centerX);
            make.centerY.mas_equalTo(self.view.mas_centerY);
            
        }];
    }else{
    //创建列表
    //有数据时创建列表
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(75, 0, SCREEN_WIDTH-130, SCREEN_HEIGHT-100) style:UITableViewStyleGrouped];
    self.myTableView.backgroundColor =UIColorFromRGB(241, 244, 248);
    self.myTableView.delegate =self;
    self.myTableView.dataSource =self;
    self.myTableView.showsVerticalScrollIndicator =NO;
    //修改索引颜色
//    self.myTableView.sectionIndexBackgroundColor = [UIColor clearColor];//修改右边索引的背景色
//    self.myTableView.sectionIndexColor = UIColorFromRGB(26, 167, 157);//修改右边索引字体的颜色
//    self.myTableView.sectionIndexTrackingBackgroundColor = [UIColor whiteColor];//修改右边索引点击时候的背景色
    //无分割线
//    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //多余的CELL 隐藏
    self.myTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.myTableView registerClass:[ChildListCell class] forCellReuseIdentifier:@"ChildListCell"];
    [self.view addSubview:self.myTableView];
        
        [self _initIndexView];
    }
}

#define kSectionIndexWidth 40.f
#define kSectionIndexHeight 460.f
- (void)_initIndexView
{
    _sectionIndexView = [[DSectionIndexView alloc] init];
    _sectionIndexView.backgroundColor = [UIColor clearColor];
    _sectionIndexView.dataSource = self;
    _sectionIndexView.delegate = self;
    _sectionIndexView.isShowCallout = YES;
    _sectionIndexView.calloutViewType = CalloutViewTypeForUserDefined;
    _sectionIndexView.calloutDirection = SectionIndexCalloutDirectionLeft;
    _sectionIndexView.calloutMargin = 100.f;
    [self.view addSubview:self.sectionIndexView];
    [_sectionIndexView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.myTableView.mas_right).with.offset(15*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.myTableView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(kSectionIndexWidth, kSectionIndexHeight));
    }];
        [self.sectionIndexView reloadItemViews];
}

#pragma mark tableViewDelegate

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return self.classBtnView;
    }else{
        return nil;
    }
}

//-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
//{
//    
//    return self.ZiMuArr;
//}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section ==0 ) {
        return (_h+85)*AutoScaleVertical;
    }else{
        return 20*AutoScaleVertical;
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section ==0) {
        return nil;
    }else{
    NSString *key = [self.ZiMuArr objectAtIndex:section];
    return key;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.ZiMuPaiXuArr.count+1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section ==0) {
        return 0;
    }else{
    return [[self.ZiMuPaiXuArr objectAtIndex:section-1] count];
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section ==0) {
        return nil;
    }
    
    ChildListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ChildListCell"];
    //cell.userInteractionEnabled = NO;
    if (cell == nil) {
        cell = [[ChildListCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier: @"ChildListCell"] ;
    }
    
    [cell relayoutUIWithModel:self.childArray[indexPath.section-1][indexPath.row]];
     return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%d",indexPath.row);
    
    PersonalInfoViewController * vc = [[PersonalInfoViewController alloc]init];
    vc.model = self.childArray[indexPath.section-1][indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
    
}


#pragma mark DSectionIndexViewDataSource && delegate method
- (NSInteger)numberOfItemViewForSectionIndexView:(DSectionIndexView *)sectionIndexView
{
    return self.myTableView.numberOfSections;
}

- (DSectionIndexItemView *)sectionIndexView:(DSectionIndexView *)sectionIndexView itemViewForSection:(NSInteger)section
{
  
//    if (section == 0) {
//        return nil;
//    }else{
    DSectionIndexItemView *itemView = [[DSectionIndexItemView alloc] init];
    
    itemView.titleLabel.text = [self.ZiMuArr objectAtIndex:section ];
    itemView.titleLabel.font = [UIFont systemFontOfSize:12];
    itemView.titleLabel.textColor = UIColorFromRGB(28, 173, 146);
    itemView.titleLabel.highlightedTextColor = [UIColor redColor];
    itemView.titleLabel.shadowColor = [UIColor whiteColor];
    itemView.titleLabel.shadowOffset = CGSizeMake(0, 1);
    
    return itemView;
//    }
}

- (UIView *)sectionIndexView:(DSectionIndexView *)sectionIndexView calloutViewForSection:(NSInteger)section
{
    
    
//    if (section == 0) {
//        return nil;
//    }else{
    UILabel *label = [[UILabel alloc] init];
    
    label.frame = CGRectMake(512, 192, 80*AutoScaleHorizontal, 80*AutoScaleVertical);
    
    
    label.backgroundColor = [UIColor clearColor];
    label.textColor = UIColorFromRGB(28, 173, 146);
    label.font = [UIFont boldSystemFontOfSize:36];
    label.text = [self.ZiMuArr objectAtIndex:section];
    label.textAlignment = UITextAlignmentCenter;
    
    [label.layer setCornerRadius:label.frame.size.width/2];
    [label.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    [label.layer setBorderWidth:3.0f];
    [label.layer setShadowColor:[UIColor blackColor].CGColor];
    [label.layer setShadowOpacity:0.8];
    [label.layer setShadowRadius:5.0];
    [label.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
    
    
    return label;
//    }
}

- (NSString *)sectionIndexView:(DSectionIndexView *)sectionIndexView
               titleForSection:(NSInteger)section
{
    
//    if (section == 0) {
//        return nil;
//    }else{
    return [self.ZiMuArr objectAtIndex:section];
//    }
}

- (void)sectionIndexView:(DSectionIndexView *)sectionIndexView didSelectSection:(NSInteger)section
{
    
    if (section == 0) {
        NSLog(@"过了");
        [self.myTableView setContentOffset:CGPointMake(0,0) animated:YES];
    }else{
    [self.myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}



#pragma mark 切换班级
-(void)chooseClass:(UIButton*)sender{
    _rightChosenTag = sender.tag-100;
    sender.selected = YES;
    sender.backgroundColor = UIColorFromRGB(26, 167, 157);
    UIImageView * img = (UIImageView*)[sender viewWithTag:sender.tag+50];
    img.hidden = NO;
    for (UIButton * btn in [self.classBtnView subviews]) {
        if ([btn isKindOfClass:[UIButton class]]) {
            if (btn.tag!=sender.tag) {
                btn.selected = NO;
                btn.backgroundColor = UIColorFromRGB(241, 246, 248);
                UIImageView * img = (UIImageView*)[btn viewWithTag:btn.tag+50];
                img.hidden = YES;
            }
        }
        
    }
    //更新显示数据源
    if (_rightChosenTag == 0) {//全选
        
    self.childArray = [[NSMutableArray alloc]initWithCapacity:0];//根据ZIMUPAIXUARR的顺序，把名字换成模型，最终显示。
    self.ZiMuArr = [[NSMutableArray alloc]initWithCapacity:0];//首字母数组
    self.ZiMuPaiXuArr = [[NSMutableArray alloc]initWithCapacity:0];//对数据以首字母重新排序的数组
    _rightNowPaixuArr = [[NSMutableArray alloc]initWithCapacity:0];//用来切换显示数据源。
    NSMutableArray * allChildArr  = [[NSMutableArray alloc]init];
    allChildArr = [_allDataDictionary objectForKey:@"ChildList"];//全部班级
    for (NSMutableDictionary * dict in allChildArr) {//默认全部
        ChildModel * model = [ChildModel modelWithDictionary:dict];
        [_rightNowPaixuArr addObject:model];
    }
    NSMutableArray * childArr = [[NSMutableArray alloc]initWithCapacity:0];//准备对孩子名字排序的数组,放孩子名
    for (ChildModel*mod in _rightNowPaixuArr) {
        [childArr addObject:mod.ChildName];
    }
    self.ZiMuArr = [ChineseString IndexArray:childArr];//sectionheader
        [self.ZiMuArr insertObject:@"☆" atIndex:0];
    self.ZiMuPaiXuArr = [ChineseString LetterSortArray:childArr];
    //将模型数组从新排序
    for (NSMutableArray* array in self.ZiMuPaiXuArr) {
        NSMutableArray * smallArray = [[NSMutableArray alloc]initWithCapacity:0];
        for (NSString*str in array) {
            for (ChildModel*mod in _rightNowPaixuArr.reverseObjectEnumerator) {
                if ([str isEqualToString:mod.ChildName]) {
                    [smallArray addObject: mod];
                    [_rightNowPaixuArr removeObject:mod];
                }
            }
        }
        [self.childArray addObject:smallArray];
    }
    }
    else{//非全选
        NSString * rightnowClassNaeme = self.schoolNameArr[_rightChosenTag-1];
        NSLog(@"现在选择的班级 :%@",rightnowClassNaeme);
        self.childArray = [[NSMutableArray alloc]initWithCapacity:0];//根据ZIMUPAIXUARR的顺序，把名字换成模型，最终显示。
        self.ZiMuArr = [[NSMutableArray alloc]initWithCapacity:0];//首字母数组
        self.ZiMuPaiXuArr = [[NSMutableArray alloc]initWithCapacity:0];//对数据以首字母重新排序的数组
        _rightNowPaixuArr = [[NSMutableArray alloc]initWithCapacity:0];//用来切换显示数据源。
        
        NSMutableArray * allChildArr  = [[NSMutableArray alloc]init];
        allChildArr = [_allDataDictionary objectForKey:@"ChildList"];//全部班级
        for (NSMutableDictionary * dict in allChildArr) {//根据班级名筛选
            if ([[dict objectForKey:@"Name"]isEqualToString:rightnowClassNaeme]) {
                ChildModel * model = [ChildModel modelWithDictionary:dict];
                [_rightNowPaixuArr addObject:model];
            }
            
        }
        NSMutableArray * childArr = [[NSMutableArray alloc]initWithCapacity:0];//准备对孩子名字排序的数组,放孩子名
        for (ChildModel*mod in _rightNowPaixuArr) {
            [childArr addObject:mod.ChildName];
        }
        self.ZiMuArr = [ChineseString IndexArray:childArr];//sectionheader
        [self.ZiMuArr insertObject:@"☆" atIndex:0];
        self.ZiMuPaiXuArr = [ChineseString LetterSortArray:childArr];
        //将模型数组从新排序
        for (NSMutableArray* array in self.ZiMuPaiXuArr) {
            NSMutableArray * smallArray = [[NSMutableArray alloc]initWithCapacity:0];
            for (NSString*str in array) {
                for (ChildModel*mod in _rightNowPaixuArr.reverseObjectEnumerator) {
                    if ([str isEqualToString:mod.ChildName]) {
                        [smallArray addObject: mod];
                        [_rightNowPaixuArr removeObject:mod];
                    }
                }
            }
            [self.childArray addObject:smallArray];
        }
    }
    NSInteger manyHeight = 0;//共多少人
    for (NSMutableArray*arr in self.childArray) {
        for (ChildModel * mod in arr) {
            manyHeight +=1;
        }
    }
    self.numberLabel.text= [NSString stringWithFormat:@"共%d人",manyHeight];
    
    [self.myTableView reloadData];
    [self.sectionIndexView reloadItemViews];
}
//添加孩子以后 更新当前数据源
-(void)chooseClassWithINT{

    //更新显示数据源
    if (_rightChosenTag == 0) {//全选
        
        self.childArray = [[NSMutableArray alloc]initWithCapacity:0];//根据ZIMUPAIXUARR的顺序，把名字换成模型，最终显示。
        self.ZiMuArr = [[NSMutableArray alloc]initWithCapacity:0];//首字母数组
        self.ZiMuPaiXuArr = [[NSMutableArray alloc]initWithCapacity:0];//对数据以首字母重新排序的数组
        _rightNowPaixuArr = [[NSMutableArray alloc]initWithCapacity:0];//用来切换显示数据源。
        NSMutableArray * allChildArr  = [[NSMutableArray alloc]init];
        allChildArr = [_allDataDictionary objectForKey:@"ChildList"];//全部班级
        for (NSMutableDictionary * dict in allChildArr) {//默认全部
            ChildModel * model = [ChildModel modelWithDictionary:dict];
            [_rightNowPaixuArr addObject:model];
        }
        NSMutableArray * childArr = [[NSMutableArray alloc]initWithCapacity:0];//准备对孩子名字排序的数组,放孩子名
        for (ChildModel*mod in _rightNowPaixuArr) {
            [childArr addObject:mod.ChildName];
        }
        self.ZiMuArr = [ChineseString IndexArray:childArr];//sectionheader
        [self.ZiMuArr insertObject:@"☆" atIndex:0];
        self.ZiMuPaiXuArr = [ChineseString LetterSortArray:childArr];
        //将模型数组从新排序
        for (NSMutableArray* array in self.ZiMuPaiXuArr) {
            NSMutableArray * smallArray = [[NSMutableArray alloc]initWithCapacity:0];
            for (NSString*str in array) {
                for (ChildModel*mod in _rightNowPaixuArr.reverseObjectEnumerator) {
                    if ([str isEqualToString:mod.ChildName]) {
                        [smallArray addObject: mod];
                        [_rightNowPaixuArr removeObject:mod];
                    }
                }
            }
            [self.childArray addObject:smallArray];
        }
    }
    else{//非全选
        NSString * rightnowClassNaeme = self.schoolNameArr[_rightChosenTag-1];
        NSLog(@"现在选择的班级 :%@",rightnowClassNaeme);
        self.childArray = [[NSMutableArray alloc]initWithCapacity:0];//根据ZIMUPAIXUARR的顺序，把名字换成模型，最终显示。
        self.ZiMuArr = [[NSMutableArray alloc]initWithCapacity:0];//首字母数组
        self.ZiMuPaiXuArr = [[NSMutableArray alloc]initWithCapacity:0];//对数据以首字母重新排序的数组
        _rightNowPaixuArr = [[NSMutableArray alloc]initWithCapacity:0];//用来切换显示数据源。
        
        NSMutableArray * allChildArr  = [[NSMutableArray alloc]init];
        allChildArr = [_allDataDictionary objectForKey:@"ChildList"];//全部班级
        for (NSMutableDictionary * dict in allChildArr) {//根据班级名筛选
            if ([[dict objectForKey:@"Name"]isEqualToString:rightnowClassNaeme]) {
                ChildModel * model = [ChildModel modelWithDictionary:dict];
                [_rightNowPaixuArr addObject:model];
            }
            
        }
        NSMutableArray * childArr = [[NSMutableArray alloc]initWithCapacity:0];//准备对孩子名字排序的数组,放孩子名
        for (ChildModel*mod in _rightNowPaixuArr) {
            [childArr addObject:mod.ChildName];
        }
        self.ZiMuArr = [ChineseString IndexArray:childArr];//sectionheader
        [self.ZiMuArr insertObject:@"☆" atIndex:0];
        self.ZiMuPaiXuArr = [ChineseString LetterSortArray:childArr];
        //将模型数组从新排序
        for (NSMutableArray* array in self.ZiMuPaiXuArr) {
            NSMutableArray * smallArray = [[NSMutableArray alloc]initWithCapacity:0];
            for (NSString*str in array) {
                for (ChildModel*mod in _rightNowPaixuArr.reverseObjectEnumerator) {
                    if ([str isEqualToString:mod.ChildName]) {
                        [smallArray addObject: mod];
                        [_rightNowPaixuArr removeObject:mod];
                    }
                }
            }
            [self.childArray addObject:smallArray];
        }
    }
    NSInteger manyHeight = 0;//共多少人
    for (NSMutableArray*arr in self.childArray) {
        for (ChildModel * mod in arr) {
            manyHeight +=1;
        }
    }
    self.numberLabel.text= [NSString stringWithFormat:@"共%d人",manyHeight];
    [self.myTableView reloadData];
    [self.sectionIndexView reloadItemViews];
    
}

//左导航按钮
-(void)leftBarBtnClicked{
    NSLog(@"左边");
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 添加孩子相关
-(void)rightBarBtnClicked{
    NSLog(@"右边");
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    self.AddChildView = [[AddChildView alloc]init];
    [window addSubview:self.AddChildView];
    [self.AddChildView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(window.mas_centerX);
        make.centerY.mas_equalTo(window.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(600*AutoScaleHorizontal, 450*AutoScaleVertical));
    }];
    
    self.AddChildView.realClassLabel = [[UILabel alloc]init];
    self.AddChildView.realClassLabel.layer.borderWidth = 1;
    self.AddChildView.realClassLabel.layer.borderColor =UIColorFromRGB(243, 243, 243).CGColor;
    [self.AddChildView.realClassLabel setTextAlignment:NSTextAlignmentCenter];
    self.AddChildView.realClassLabel.text = @"未分班";
    self.AddChildView.realClassLabel.textColor = UIColorFromRGB(79, 79, 79);
    self.AddChildView.realClassLabel.font = [UIFont systemFontOfSize:18*AutoScaleHorizontal];
    [self.AddChildView addSubview:self.AddChildView.realClassLabel];
    [self.AddChildView.realClassLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.AddChildView.classLabel.mas_right).with.offset(70*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.AddChildView.classLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    self.AddChildView.arrowView1 = [[UIImageView alloc]init];
    self.AddChildView.arrowView1.image = [UIImage imageNamed:@"arrowView"];
    [self.AddChildView addSubview:self.AddChildView.arrowView1];
    [self.AddChildView.arrowView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.AddChildView.realClassLabel.mas_right).with.offset(-15*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.AddChildView.realClassLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10*AutoScaleHorizontal, 10*AutoScaleVertical));
    }];
    
    self.AddChildView.realClassBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.AddChildView.realClassBtn.backgroundColor = [UIColor clearColor];
    //    [self.realBirthBtn addTarget:self action:@selector(birthChoose) forControlEvents:UIControlEventTouchUpInside];
    [self.AddChildView addSubview:self.AddChildView.realClassBtn];
    [self.AddChildView.realClassBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self.AddChildView.realClassLabel);
    }];
    //第一次迭代增加负责教师
    self.AddChildView.responsTeacher = [[UILabel alloc]init];
    self.AddChildView.responsTeacher.text = @"负责教师";
    self.AddChildView.responsTeacher.textColor = [UIColor blackColor];
    [self.AddChildView.responsTeacher setTextAlignment:NSTextAlignmentLeft];
    self.AddChildView.responsTeacher.font = [UIFont systemFontOfSize:18*AutoScaleHorizontal];
    [self.AddChildView addSubview:self.AddChildView.responsTeacher];
    [self.AddChildView.responsTeacher mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.AddChildView.classLabel.mas_bottom).with.offset(30*AutoScaleVertical);
        make.left.mas_equalTo(self.AddChildView.mas_left).with.offset(75*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(75*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    self.AddChildView.teacherText = [[UITextField alloc]init];
    //    self.nameText.delegate =self;
    self.AddChildView.teacherText.layer.borderWidth = 1;
    self.AddChildView.teacherText.layer.borderColor =UIColorFromRGB(243, 243, 243).CGColor;
    [self.AddChildView addSubview:self.AddChildView.teacherText];
    [self.AddChildView.teacherText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.AddChildView.responsTeacher.mas_right).with.offset(70*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.AddChildView.responsTeacher.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    //将家长电话下移
    [self.AddChildView.phoneLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.AddChildView.responsTeacher.mas_bottom).with.offset(30*AutoScaleVertical);
        make.left.mas_equalTo(self.AddChildView.mas_left).with.offset(75*AutoScaleHorizontal);
        make.size.mas_equalTo(CGSizeMake(75*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
    [self.AddChildView.PhoneText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.AddChildView.phoneLabel.mas_right).with.offset(70*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.AddChildView.phoneLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    ///////////////////////////////////////////////////////////////////////
    //选取班级
    NSInteger taga = 0;
    self.scrollBackView = [[UIView alloc]init];
    UITapGestureRecognizer * scTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapSC)];
    [self.scrollBackView addGestureRecognizer:scTap];
    self.scrollBackView.backgroundColor = [UIColor clearColor];
    [window addSubview:self.scrollBackView];
    [self.scrollBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self.view);
    }];
    
    self.choosClassScrollView =[[UIScrollView alloc]init];
    self.choosClassScrollView.backgroundColor = [UIColor clearColor];
    [self.scrollBackView addSubview:self.choosClassScrollView];
    [self.choosClassScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.AddChildView.realClassLabel.mas_bottom);
        make.left.mas_equalTo(self.AddChildView.realClassLabel.mas_left);
        make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 180*AutoScaleVertical));
    }];
    self.choosClassScrollView.contentSize=CGSizeMake(0, 30*self.schoolNameArr.count*AutoScaleVertical);
        for (NSString * str in self.schoolNameArr) {
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.layer.borderWidth =1;
            btn.layer.borderColor = UIColorFromRGB(188, 188, 188).CGColor;
            [btn setTitle:str forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:18*AutoScaleHorizontal];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.backgroundColor = UIColorFromRGB(26, 167, 157);
            btn.tag = 1000+taga;
            [btn addTarget:self action:@selector(chooseClassWithSender:) forControlEvents:UIControlEventTouchUpInside];
            [self.choosClassScrollView addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.choosClassScrollView.mas_top).with.offset(taga*30*AutoScaleVertical);
                make.left.mas_equalTo(self.choosClassScrollView.mas_left);
                make.size.mas_equalTo(CGSizeMake(250*AutoScaleHorizontal, 30*AutoScaleVertical));
            }];
            
            taga++;
        }
    self.scrollBackView.hidden = YES;
    /////////////////////////////////////////////////////////////
    
    self.AddChildView.nameText.delegate  =self;
    self.AddChildView.PhoneText.delegate  =self;
    [self.AddChildView.cancelBtn addTarget:self action:@selector(pressCancel) forControlEvents:UIControlEventTouchUpInside];
    [self.AddChildView.realBirthBtn addTarget:self action:@selector(pressBirth) forControlEvents:UIControlEventTouchUpInside];
    [self.AddChildView.realClassBtn addTarget:self action:@selector(pressClass) forControlEvents:UIControlEventTouchUpInside];
    [self.AddChildView.confirmBtn addTarget:self action:@selector(pressConfirm) forControlEvents:UIControlEventTouchUpInside];
}
//取消添加
-(void)pressCancel{
    [_backView removeFromSuperview];
    [self.AddChildView.realClassView removeFromSuperview];
    [self.AddChildView removeFromSuperview];
    
}
//点击生日调取日历
-(void)pressBirth{
    [self.AddChildView.PhoneText resignFirstResponder];
    [self.AddChildView.teacherText resignFirstResponder];
    [self.AddChildView.nameText resignFirstResponder];
    _datePickerView = [[SDDatePickerView alloc]init];
    _datePickerView.delegate = self;
}
// 日历代理方法
-(void)cancelBtnClick{
    NSLog(@"取消日历");
}
- (void)sureBtnWithDate:(NSString *)dateStr
{
    NSLog(@"选择日历");
    self.AddChildView.realBirthLabel.text = dateStr;
}
// 选取班级下拉框
-(void)pressClass{
    [self.AddChildView.PhoneText resignFirstResponder];
    [self.AddChildView.teacherText resignFirstResponder];
    [self.AddChildView.nameText resignFirstResponder];
    self.scrollBackView.hidden = NO;
}

-(void)tapSC{
    self.scrollBackView.hidden = YES;
}
//确定选取班级
-(void)chooseClassWithSender:(UIButton*)sender{
    self.scrollBackView.hidden = YES;
    self.AddChildView.realClassLabel.text = sender.titleLabel.text;
//    self.AddChildView.realClassView.hidden = YES;
}
//确定添加孩子
-(void)pressConfirm{
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    if (self.AddChildView.nameText.text.length == 0) {
        [self showMessage:@"孩子姓名不能为空"];
    }
    else if (self.AddChildView.realBirthLabel.text.length == 0) {
        [self showMessage:@"孩子生日不能为空"];
    }
    else if (self.AddChildView.realClassLabel.text.length == 0) {
        [self showMessage:@"孩子班级不能为空"];
    }
    else{
        NSLog(@"添加成功");
        NSMutableDictionary * newChildDic = [[NSMutableDictionary alloc]init];
        //找到班级ID
        NSNumber * newClassid = @0;
        NSMutableArray * allClassArr  = [[NSMutableArray alloc]init];
        allClassArr = [_allDataDictionary objectForKey:@"ClassList"];//全部班级
        for (NSDictionary * dic in allClassArr) {
            if ([[dic objectForKey:@"Name"]isEqualToString:self.AddChildView.realClassLabel.text]) {
                newClassid = [dic objectForKey:@"Id"];
            }
        }
        //性别
        NSNumber * newGender = @0;
        if (self.AddChildView.boyBtn.selected ==YES) {
            newGender = @1;
        }else{
            newGender = @2;
        }
        
        //获取当前时间
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        NSDate *datenow = [NSDate date];
        NSString *currentTimeString = [formatter stringFromDate:datenow];
        NSString * currentTime = [currentTimeString substringWithRange:NSMakeRange(0, 10)];
        
        //新ID
        NSInteger newbabyId = [[user objectForKey:@"CreatChildId"]integerValue]-1;
        NSNumber * babyId = [NSNumber numberWithInt:newbabyId];
        [user removeObjectForKey:@"CreatChildId"];
        [user setObject:babyId forKey:@"CreatChildId"];
        
        [newChildDic setObject:self.AddChildView.realBirthLabel.text forKey:@"Birthday"];
        [newChildDic setObject:self.AddChildView.nameText.text forKey:@"ChildName"];
        [newChildDic setObject:currentTime forKey:@"CreateTime"];
        [newChildDic setObject:newGender forKey:@"Gender"];
        [newChildDic setObject:newClassid forKey:@"ClassId"];
        [newChildDic setObject:self.AddChildView.realClassLabel.text forKey:@"Name"];
        [newChildDic setObject:self.AddChildView.PhoneText.text forKey:@"Phone"];
        [newChildDic setObject:[user objectForKey:@"AgencyId"]  forKey:@"ServiceUnitId"];
        [newChildDic setObject:self.AddChildView.teacherText.text forKey:@"ResponsibleTeacher"];
        [newChildDic setObject:babyId forKey:@"Id"];
        
        
        //更新数据源
        NSMutableArray * arr = [_allDataDictionary objectForKey:@"ChildList"];
        [arr insertObject:newChildDic atIndex:0];
//        [arr addObject:newChildDic];
        [_allDataDictionary removeObjectForKey:@"ChildList"];
        [_allDataDictionary setObject:arr forKey:@"ChildList"];
        NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
        NSString * allStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [user removeObjectForKey:@"AllData"];
        [user setObject:allStr forKey:@"AllData"];
        [user synchronize];
        [_backView removeFromSuperview];
        [self.AddChildView removeFromSuperview];
//        [self.myScrollView removeFromSuperview];
        if (self.childArray.count ==0) {
//            for (UIView * view in self.view) {
//                [view removeFromSuperview];
//            }
            [_noDataLabel removeFromSuperview];
            [self getData];
        }else{
        
        [self chooseClassWithINT];
        }
        [self showMessage:@"添加孩子成功"];
        
    }
}


#pragma mark ---- 键盘代理输入限制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField==self.AddChildView.nameText) {
        
    
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ALPHANUM] invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    return [string isEqualToString:filtered];
    }else{
        return [self validateNumberWithDouHao:string];
    }
    
}
//可以输入逗号
- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@".-0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}
//不能输入逗号
- (BOOL)validateNumberWithDouHao:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"-0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}

#pragma mark ---- 根据键盘高度将当前视图向上滚动同样高度
///键盘显示事件
- (void)keyboardWillShoww:(NSNotification *)notification {
    //获取键盘高度，在不同设备上，以及中英文下是不同的
    CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
    
    //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
    CGFloat offset = kbHeight;
    
    // 取得键盘的动画时间，这样可以在视图上移的时候更连贯
    double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //将视图上移计算好的偏移
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    if(offset > 0) {
        [UIView animateWithDuration:duration animations:^{
            window.frame = CGRectMake(0.0f, -85*AutoScaleVertical, window.frame.size.width, window.frame.size.height);
        }];
    }
}



#pragma mark ---- 当键盘消失后，视图需要恢复原状



///键盘消失事件
- (void)keyboardWillHidee:(NSNotification *)notify {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    //视图下沉恢复原状
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    [UIView animateWithDuration:duration animations:^{
        window.frame = CGRectMake(0, 0, window.frame.size.width, window.frame.size.height);
    }];
}
// 释放
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
